﻿#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
using std::cin;
using std::cout;
using std::endl;
using std::string;
void Error(const string &msg)
{
  cout << msg << " error!" << endl;
  exit(-1);
}
void Print(const string &msg)
{
  cout << msg << endl;
}
int main(int args, char *argv[])
{

  auto hostent = gethostbyname(argv[1]);
  if (hostent == NULL)
    Error("gethostbyname()");
  cout << argv[1] << "对应的官方域名为：" << hostent->h_name << endl;
  cout << argv[1] << "对应的其它域名为：" << endl;
  for (int i = 0; hostent->h_aliases[i]; ++i)
    cout << hostent->h_aliases[i] << endl;
  cout << argv[1] << "的地址类型" << hostent->h_addrtype << endl;
  cout << argv[1] << "的IP地址为：" << endl;
  for (int i = 0; hostent->h_addr_list[i]; ++i)
    cout << inet_ntoa(*(struct in_addr *)hostent->h_addr_list[i]) << endl;
  return 0;
}